package com.ruoyi.lvlian.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.MD5Utils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.lvlian.mapper.StationMapper;
import com.ruoyi.lvlian.domain.Station;
import com.ruoyi.lvlian.service.IStationService;

/**
 * 站点Service业务层处理
 *
 * @author lvlian
 * @date 2025-04-22
 */
@Service
public class StationServiceImpl implements IStationService {
    @Autowired
    private StationMapper stationMapper;

    /**
     * 查询站点
     *
     * @param id 站点主键
     * @return 站点
     */
    @Override
    public Station selectStationById(String id) {
        return stationMapper.selectStationById(id);
    }

    /**
     * 查询站点列表
     *
     * @param station 站点
     * @return 站点
     */
    @Override
    public List<Station> selectStationList(Station station) {
        return stationMapper.selectStationList(station);
    }

    /**
     * 新增站点
     *
     * @param station 站点
     * @return 结果
     */
    @Override
    public int insertStation(Station station) {
        station.setId(    MD5Utils.md5(  station.getName() ) );
        station.setCreateUser(SecurityUtils.getUsername());
        station.setCreateDate(DateUtils.getCurrentTime());
        return stationMapper.insertStation(station);
    }

    /**
     * 修改站点
     *
     * @param station 站点
     * @return 结果
     */
    @Override
    public int updateStation(Station station) {
        int updateResult = stationMapper.updateStation(station);
        if (0 == updateResult) {
            updateResult = insertStation(station);
        }

        return updateResult;


    }

    /**
     * 批量删除站点
     *
     * @param ids 需要删除的站点主键
     * @return 结果
     */
    @Override
    public int deleteStationByIds(String[] ids) {
        return stationMapper.deleteStationByIds(ids);
    }

    /**
     * 删除站点信息
     *
     * @param id 站点主键
     * @return 结果
     */
    @Override
    public int deleteStationById(String id) {
        return stationMapper.deleteStationById(id);
    }
}
